package com.zhang.dao;

import com.zhang.pojo.Department;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhangJunqi
 * @Date 2022/2/19 -10:45
 */
@Repository
public class DepartmentDao {
    private static Map<Integer, Department> departmentsMap;
    static {
        departmentsMap=new HashMap<Integer, Department> ();
        departmentsMap.put (101,new Department (101,"运维产品部"));
        departmentsMap.put (102,new Department (102,"联锁部"));
        departmentsMap.put (103,new Department (103,"CC部"));
        departmentsMap.put (104,new Department (104,"ATS部"));
    }
    public Collection<Department> getAllDepartment(){
        return departmentsMap.values ();
    }
    public Department getDepartmentById(Integer id){
        return departmentsMap.get (id);
    }
    public Department getDepartmentByName(String name){
        Collection<Department> departmentValues = departmentsMap.values ();
        Department department=null;
        for(Department departmentValue: departmentValues){
            if(department.getDepartmentName ().equals (name)){
                department=departmentValue;
            }
        }
        return department;
    }
}
